/*****************************************************************
 *@Copyright all rights reserved © 2014 Yuga
 *@author Oplink OMS
 *Contact: zengkang007@gmail.com
 *****************************************************************/
package com.oplink.webems.modules.sys.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

import com.oplink.webems.common.persistence.BaseDao;
import com.oplink.webems.common.persistence.BaseDaoImpl;
import com.oplink.webems.modules.sys.entity.CfgValue;

/**
 * 配置值DAO接口
 * 
 * @author Oplink OMS
 * @version 2014-09-02
 */
public interface CfgValueDao extends CfgValueDaoCustom, CrudRepository<CfgValue, Long> {

	@Modifying
	@Query("update CfgValue set delFlag='" + CfgValue.DEL_FLAG_DELETE + "'")
	public int deleteById(Long id);

	@Query("from CfgValue where delFlag='" + CfgValue.DEL_FLAG_NORMAL + "'")
	public List<CfgValue> findAllById(Long id);

	@Query("from CfgValue where delFlag='" + CfgValue.DEL_FLAG_NORMAL
			+ "' AND formId =?1 AND user.id = ?2 AND catalog = ?3")
	public List<CfgValue> findForm(String formId, Long id, String catalog);

	/**
	 * 获取记录标识位
	 * 
	 * @param uid
	 * @return
	 */
	@Query("SELECT DISTINCT formId FROM CfgValue where delFlag='" + CfgValue.DEL_FLAG_NORMAL
			+ "' AND user.id = ?1 AND catalog = ?2")
	public List<String> findFormID(Long uid, String catalog);
}

/**
 * DAO自定义接口
 * 
 * @author Oplink OMS
 */
interface CfgValueDaoCustom extends BaseDao<CfgValue> {
}

/**
 * DAO自定义接口实现
 * 
 * @author Oplink OMS
 */
@Component
class CfgValueDaoImpl extends BaseDaoImpl<CfgValue> implements CfgValueDaoCustom {
}